home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Sound / Subspace68k / src / Subspace.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-05-04  |  32.8 KB  |  1,275 lines

  1. #define P96 //SuRgEoN :for compatibility - still through cgfx
  2.  
  3. #define MAXWIDTH  640
  4. #define MAXHEIGHT 480
  5.  
  6. #define NUMFIELDS 19
  7. #define NUMWAVES 12
  8.  
  9.  
  10. #ifdef __VBCC__  //SuRgEoN
  11. #define   M_PI 3.14159265358979323846
  12. #endif
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <time.h>
  18. #include <math.h>
  19.  
  20. #include <exec/types.h>
  21. #include <exec/memory.h>
  22. #include <proto/exec.h>
  23. #include <proto/dos.h>
  24. #include <proto/intuition.h>
  25. #include <proto/graphics.h>
  26. #include <proto/cybergraphics.h>
  27. #include <proto/icon.h>
  28. #include <proto/keymap.h>
  29. #include <devices/timer.h>
  30. #include <proto/timer.h>
  31. #include <exec/devices.h>
  32.  
  33. #include <workbench/startup.h>
  34. #include <dos/dostags.h>
  35. #include <graphics/gfxbase.h>
  36. #include <cybergraphx/cybergraphics.h>
  37.  
  38. #ifdef __SASC
  39. struct Library *PPCLibBase;
  40. #include <PowerUP/PPCLib/tasks.h>
  41. ULONG    PPCCallOS(struct Caos*);
  42. ULONG    PPCSetTaskAttrs(void*, struct TagItem*);
  43.  
  44. #define    PPCSetTaskAttrs(TaskObject, Tags)    _PPCSetTaskAttrs(PPC_BASE_NAME, TaskObject, Tags)
  45. static __inline ULONG _PPCSetTaskAttrs(void *PPCLibBase, void*TaskObject, struct TagItem*Tags) {
  46.     struct Caos    MyCaos;
  47.     MyCaos.M68kCacheMode    =    IF_CACHEFLUSHALL;
  48.     MyCaos.PPCCacheMode    =    IF_CACHEFLUSHALL;
  49.     MyCaos.a0        =(ULONG) TaskObject;
  50.     MyCaos.a1        =(ULONG) Tags;
  51.     MyCaos.caos_Un.Offset    =    (-192);
  52.     MyCaos.a6        =(ULONG) PPCLibBase;    
  53.     return((ULONG)PPCCallOS(&MyCaos));
  54. }
  55. #endif
  56.  
  57.  
  58. #include "TrackInfo.h"
  59.  
  60. BOOL PluginInit(int argc, char **argv);
  61. void PluginExit(void);
  62. void PluginLoop(void); //mainloop for viasualization effects
  63. void ShowRequester(char *Text, char *Button);
  64. struct MsgPort *MyCreatePort(UBYTE *name, LONG pri);
  65. void MyDeletePort(struct MsgPort *mp);
  66.  
  67. /***************************************************************************/
  68. /* This is the global variables section. Don't change anything here unless */
  69. /* you know what you're doing!                                             */
  70. /***************************************************************************/
  71.  
  72. BYTE             PluginSignal, InfoSignal, ConfigSignal;
  73. ULONG            PluginMask,   InfoMask,   ConfigMask;
  74. BOOL             Accepted;
  75. struct Process   *PluginTask;
  76. struct MsgPort   *PluginMP;
  77. struct MsgPort   *PluginRP;
  78. struct TrackInfo *tinfo;
  79.  
  80. #ifdef __SASC
  81. struct Library     *TimerBase;
  82. #else
  83.  #ifdef __VBCC__ //SuRgEoN
  84. struct Library      *TimerBase = NULL;
  85.  #else
  86. struct Device      *TimerBase;
  87.  #endif
  88. #endif
  89. struct MsgPort     *TimerMP;
  90. struct timerequest *TimerIO = NULL;
  91. struct EClockVal   ev1;
  92. struct EClockVal   ev2;
  93. BYTE               TimerError = -1;
  94. ULONG              EFreq=0;
  95. ULONG              TimerMask;
  96.  
  97. UWORD    TrackInfoPos = 1;
  98.  
  99. UWORD    *PluginRawL;
  100. UWORD    *PluginRawR;
  101. WORD    *PluginSamples;
  102. UWORD    *SpecRawL;
  103. UWORD    *SpecRawR;
  104. WORD *SampleRaw;
  105.  
  106. struct PluginMessage {
  107.     struct Message   msg;
  108.     ULONG            PluginMask;
  109.     struct Process   *PluginTask;
  110.     UWORD            **SpecRawL;
  111.     UWORD            **SpecRawR;
  112.     UWORD            Accepted;
  113.     UWORD            reserved0;
  114.     ULONG            InfoMask;
  115.     struct TrackInfo **tinfo;
  116.     ULONG            ConfigMask;
  117.     WORD             **SampleRaw;
  118. };
  119.  
  120. BOOL OpenTimer(void);
  121. void CloseTimer(void);
  122. void StartTimer(void);
  123.  
  124. /***************************************************************************/
  125. /* This is the main part. Again, don't change anything here if you haven't */
  126. /* got a very good reason to do so!                                        */
  127. /***************************************************************************/
  128.  
  129. int main(int argc, char **argv) {
  130.     struct PluginMessage *PluginMsg;
  131.     struct PluginMessage *ReplyMsg;
  132.  
  133.     /* Allocate all user resources */
  134.     if(PluginInit(argc, argv)) {
  135.         /* Check if a plugin capable instance of AmigaAMP is running */
  136.         if(PluginMP=FindPort("AmigaAMP plugin port"))    {
  137.             /* Allocate some sigbits for receiving signals FROM AmigaAMP */
  138.             PluginSignal = AllocSignal(-1);
  139.             ConfigSignal = AllocSignal(-1);
  140.             InfoSignal   = AllocSignal(-1);
  141.             PluginTask   = (struct Process *)FindTask(NULL);
  142.  
  143.             if(PluginSignal != -1 && InfoSignal != -1 && PluginSignal != -1) {
  144.                 PluginMask = 1L << PluginSignal;
  145.                 ConfigMask = 1L << ConfigSignal;
  146.                 InfoMask   = 1L << InfoSignal;
  147.  
  148.                 /* Allocate a message and reply port for sending messages TO AmigaAMP */
  149.                 #if defined (__SASC) || defined (__VBCC__) //SuRgEoN
  150. #ifdef __PPC__
  151.                 PluginMsg=PPCAllocVec(sizeof(struct PluginMessage), MEMF_PUBLIC|MEMF_CLEAR);
  152. #else
  153.                 PluginMsg=AllocVec(sizeof(struct PluginMessage), MEMF_PUBLIC|MEMF_CLEAR);
  154. #endif
  155.                 PluginRP=(struct MsgPort*)MyCreatePort(0,0);
  156.                 #else
  157.                 PluginMsg=AllocVecPPC(sizeof(struct PluginMessage), MEMF_PUBLIC|MEMF_CLEAR, 0);
  158.  
  159.                 PluginRP=(struct MsgPort*)CreatePort(0,0);
  160.                 #endif
  161.  
  162.                 /* Tell AmigaAMP all the details it needs to know */
  163.                 PluginMsg->msg.mn_Node.ln_Type = NT_MESSAGE;
  164.                 PluginMsg->msg.mn_Length       = sizeof(struct PluginMessage);
  165.                 PluginMsg->msg.mn_ReplyPort    = PluginRP;
  166.                 PluginMsg->PluginMask          = PluginMask;
  167.                 PluginMsg->PluginTask          = PluginTask;
  168.                 PluginMsg->SpecRawL            = &SpecRawL;
  169.                 PluginMsg->SpecRawR            = &SpecRawR;
  170.                 PluginMsg->InfoMask            = InfoMask;
  171.                 PluginMsg->tinfo               = &tinfo;
  172.                 PluginMsg->ConfigMask          = ConfigMask;
  173.                 PluginMsg->SampleRaw           = &SampleRaw;
  174.                 PutMsg(PluginMP, (struct Message *)PluginMsg);
  175.                 /* Wait for a reply */
  176.                 WaitPort(PluginRP);
  177.                 /* Let's see if AmigaAMP accepted our registration attempt */
  178.                 if(ReplyMsg = (struct PluginMessage *)GetMsg(PluginRP)) Accepted=ReplyMsg->Accepted;
  179.                 else Accepted=FALSE;
  180.  
  181.                 if(Accepted) {
  182.                     /* If it did, start the plugin loop */
  183.                     printf("Init ok! - entering plugin loop\n");
  184.                     PluginLoop();
  185.  
  186.                     /* Tell AmigaAMP that this plugin is going down */
  187.                     PluginMsg->PluginMask          = 0;
  188.                     PluginMsg->PluginTask          = NULL;
  189.                     PluginMsg->SpecRawL            = NULL;
  190.                     PluginMsg->SpecRawR            = NULL;
  191.                     PluginMsg->ConfigMask          = 0;
  192.                     PluginMsg->InfoMask            = 0;
  193.                     PluginMsg->tinfo               = NULL;
  194.                     PluginMsg->SampleRaw           = NULL;
  195.                     PutMsg(PluginMP, (struct Message *)PluginMsg);
  196.                     /* Wait for confirmation before going on! */
  197.                     WaitPort(PluginRP);
  198.                     GetMsg(PluginRP);
  199.                     /* Now that AmigaAMP knows that we're gone, we can quit */
  200.                 }
  201.                 else {
  202.                     /* If AmigaAMP didn't accept us, tell the user about it */
  203.                     ShowRequester("Plugin rejected by AmigaAMP!\nPerhaps there's another one running.", "Abort");
  204.                 }
  205.  
  206.                 /* Free all resources */
  207.                 #ifdef __SASC
  208.  
  209.                     PPCFreeVec(PluginMsg);
  210.                     MyDeletePort(PluginRP);
  211.                 #else
  212.                     #ifndef PPC__ //SuRgEoN
  213.                     FreeVec(PluginMsg);
  214.                     DeletePort(PluginRP);
  215.                     #else
  216.                     FreeVecPPC(PluginMsg);
  217.                     DeletePort(PluginRP);
  218.                     #endif
  219.                 #endif
  220.             }
  221.             else {
  222.                 ShowRequester("Signal allocation failure!", "Abort");
  223.             }
  224.             if(PluginSignal != -1) FreeSignal(PluginSignal);
  225.             if(ConfigSignal != -1) FreeSignal(ConfigSignal);
  226.             if(InfoSignal   != -1) FreeSignal(InfoSignal);
  227.         }
  228.         else {
  229.             ShowRequester("Could not find message port!\nAmigaAMP probably not running.", "Abort");
  230.         }
  231.     }
  232.     else {
  233.         ShowRequester("Plugin initialisation failed!", "Ok");
  234.     }
  235.     /* Free all user resources */
  236.     PluginExit();
  237. }
  238.  
  239. /*****************************************************************************/
  240. /* Ok, now for the individual plugin sourcecode. Everything below should be  */
  241. /* changed to your needs.                                                    */
  242. /* Just like before, we start with the global variables section              */
  243. /*****************************************************************************/
  244.  
  245. void InitWave(UBYTE WaveNum, ULONG BufNum);
  246. void CalcWave(UBYTE WaveNum, ULONG BufNum);
  247. void DrawWave(LONG *WaveX, LONG *WaveY, ULONG Width, ULONG Height, UBYTE WaveNum, ULONG BufNum);
  248.  
  249. void InitField(LONG *Zoom, ULONG Width, ULONG Height);
  250. void PrepareConstants(UBYTE FieldNum);
  251. void CalcLine(LONG *Zoom, ULONG Width, ULONG Height, UBYTE FieldNum);
  252. void MakeCMap(void);
  253. void Blur(UBYTE *PixelC, UBYTE *PixelD);
  254. void ReColor(void);
  255. void MakeTitle(void);
  256. float rnd(float max);
  257. float sgn(float val);
  258.  
  259. const char VersionString[]="\0$VER: Subspace 1.1 (10.11.00)";
  260. const char Line1[]="Subspace";
  261. const char Line2[]="by Thomas Wenzel";
  262.  
  263. #define PRECISION PRECISION_EXACT
  264.  
  265. struct IntuitionBase *IntuitionBase = NULL;
  266. struct GfxBase *GfxBase      = NULL;
  267. struct Library *IconBase     = NULL;
  268. struct Library *KeymapBase   = NULL;
  269. struct Library *AslBase      = NULL;
  270. struct Library *GadToolsBase = NULL;
  271. struct Library *CyberGfxBase = NULL;
  272. struct Screen  *PluginScreen = NULL;
  273. struct Window  *PluginWin    = NULL;
  274. struct RastPort *rp;
  275. struct ViewPort *vp;
  276.  
  277.  
  278. struct EClockVal ev1;
  279. struct EClockVal ev2;
  280.  
  281.  
  282. ULONG ModeID;
  283. ULONG WinMask;
  284.  
  285. UBYTE *PixelD;
  286. UBYTE *PixelC;
  287. ULONG *Colour;
  288.  
  289. UWORD *EmptyPointer;
  290.  
  291. char InfoLine[256];
  292.  
  293. LONG Zoom[MAXWIDTH*MAXHEIGHT];
  294. LONG Zoom2[MAXWIDTH*MAXHEIGHT];
  295. LONG WaveX[MAXWIDTH*2];
  296. LONG WaveY[MAXWIDTH*2];
  297. LONG WaveX2[MAXWIDTH*2];
  298. LONG WaveY2[MAXWIDTH*2];
  299.  
  300. ULONG MidR[4], MidG[4], MidB[4];
  301. ULONG DisplayFPS;
  302. ULONG ShowWave;
  303. ULONG LimitFPS;
  304. ULONG ScreenSize = 100;
  305. ULONG Width      = 320;
  306. #ifdef PPC
  307. ULONG Height     = 240;
  308. ULONG HalfHeight = 120;
  309. #else
  310. ULONG Height     = 200;
  311. ULONG HalfHeight = 100;
  312. #endif
  313.  
  314. ULONG Cutoff     = 1;
  315. ULONG InfoCount;
  316. ULONG FrameCountLow;
  317. ULONG FrameCountHigh;
  318. ULONG FrameCountWave;
  319. ULONG FrameCountField;
  320. ULONG TimeWave;
  321. ULONG DestWaveNum;
  322. ULONG DestWaveBuffer;
  323. float WaveMorph;
  324. ULONG MidRdst[3], MidGdst[3], MidBdst[3];
  325. ULONG LineToCalc;
  326. UBYTE FieldToCalc;
  327. UBYTE WaveToCalc, WaveToCalc0, WaveToCalc1;
  328. UBYTE PrevField;
  329.  
  330. /****************************************************************************/
  331. /* This function will be called once when the plugin is started. You should */
  332. /* allocate all needed resources here. Return TRUE if all went well.        */
  333. /****************************************************************************/
  334.  
  335. BOOL PluginInit(int argc, char **argv) {
  336.     long i,xs,ys,xd,yd,ysp,ydp;
  337.     float xf,yf;
  338.     UBYTE **ttypes;
  339.     char *str;
  340.     struct DiskObject *IconObj;
  341.     struct WBStartup  *WBStart;
  342.     #ifdef __SASC
  343.     void *ThisTask;
  344.     #else
  345.     struct TaskPPC *ThisTask;
  346.     #endif
  347.     WORD Length;
  348.  
  349. #ifdef __PPC__
  350.     struct TagItem ModeIDtags[] = {
  351.         CYBRBIDTG_Depth, 8, CYBRBIDTG_NominalWidth, 320, CYBRBIDTG_NominalHeight, 240, TAG_DONE
  352.     };
  353. #else
  354.     struct TagItem ModeIDtags[] = {
  355.         CYBRBIDTG_Depth, 8, CYBRBIDTG_NominalWidth, 320, CYBRBIDTG_NominalHeight, 200, TAG_DONE
  356.     };
  357. #endif
  358.     AslBase=OpenLibrary("asl.library", 0);
  359.     if(!AslBase) {
  360.         ShowRequester("Can't open asl.library!", "Abort");
  361.         return(FALSE);
  362.     }
  363.  
  364.     IconBase=OpenLibrary("icon.library", 0);
  365.     if(!IconBase) {
  366.         ShowRequester("Can't open icon.library!", "Abort");
  367.         return(FALSE);
  368.     }
  369.  
  370.     KeymapBase=OpenLibrary("keymap.library", 0);
  371.     if(!KeymapBase) {
  372.         ShowRequester("Can't open keymap.library!", "Abort");
  373.         return(FALSE);
  374.     }
  375.  
  376.     IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library", 0);
  377.     if(!IntuitionBase) {
  378.         ShowRequester("Can't open intuition.library!", "Abort");
  379.         return(FALSE);
  380.     }
  381.  
  382.     GadToolsBase=OpenLibrary("gadtools.library", 0);
  383.     if(!GadToolsBase) {
  384.         ShowRequester("Can't open gadtools.library!", "Abort");
  385.         return(FALSE);
  386.     }
  387.  
  388.     GfxBase=(struct GfxBase*)OpenLibrary("graphics.library", 0);
  389.     if(!GfxBase) {
  390.         ShowRequester("Can't open graphics.library!", "Abort");
  391.         return(FALSE);
  392.     }
  393.  
  394.     if(GfxBase->LibNode.lib_Version < 39) {
  395.         ShowRequester("This plugin requires AmigaOS 3.0 or greater!", "Abort");
  396.         return(FALSE);
  397.     }
  398.  
  399.     CyberGfxBase=OpenLibrary("cybergraphics.library", 40);
  400.     if(!CyberGfxBase) {
  401.         ShowRequester("This plugin requires CyberGraphX v3 or higher!", "Abort");
  402.         return(FALSE);
  403.     }
  404.  
  405.     #ifdef __SASC
  406.         /* Increase the priority of the 68k mirror task */
  407.         SetTaskPri(FindTask(NULL), 15);
  408.         /* Increase our own priority (if it only would work...) */
  409.         PPCSetTaskAttr(PPCTASKTAG_PRIORITY, 15);
  410.     #else
  411.         #ifdef __VBCC__
  412.     //        SetTaskPri(FindTask(NULL), 15);
  413.         #else
  414.         /* Increase our own priority */
  415.         ThisTask = FindTaskPPC(NULL);
  416.         SetNiceValue(ThisTask, -15);
  417.         #endif
  418.     #endif
  419.  
  420.     WBStart=(struct WBStartup *)argv;
  421.  
  422. // if(argc==0) printf("IconName: %s\n", WBStart->sm_ArgList[0].wa_Name);
  423.  
  424.     if(argc==0) IconObj=GetDiskObject(WBStart->sm_ArgList[0].wa_Name);
  425.     else        IconObj=GetDiskObject(argv[0]);
  426.  
  427.     LimitFPS = 999;
  428.  
  429.     if(IconObj) {
  430. #ifdef __VBCC__
  431.         if(str=FindToolType(&IconObj->do_ToolTypes,"MAXFPS"))
  432.         {
  433.             LimitFPS = atol(str);
  434.         }
  435.  
  436.         if(str=FindToolType(&IconObj->do_ToolTypes,"RESOLUTION"))
  437.         {
  438.             if(stricmp(str,"high") == 0) {
  439.                 Width      = 640;
  440.                 Height     = 480;
  441.                 ScreenSize = 66;
  442.             }
  443.             else {
  444.                 Width      = 320;
  445. #ifdef __PPC__
  446.                 Height     = 240;
  447. #else
  448.                 Height       = 200;
  449. #endif
  450.                 ScreenSize = 100;
  451.             }
  452.         }
  453.         if(str=FindToolType(&IconObj->do_ToolTypes,"SCREENSIZE"))
  454.         {
  455.             ScreenSize = atol(str);
  456.         }
  457.         FreeDiskObject(IconObj);
  458. #else
  459.         if(str=FindToolType(IconObj->do_ToolTypes,"MAXFPS"))
  460.         {
  461.             LimitFPS = atol(str);
  462.         }
  463.  
  464.         if(str=FindToolType(IconObj->do_ToolTypes,"RESOLUTION"))
  465.         {
  466.             if(stricmp(str,"high") == 0) {
  467.                 Width      = 640;
  468.                 Height     = 480;
  469.                 ScreenSize = 66;
  470.             }
  471.             else {
  472.                 Width      = 320;
  473. #ifdef __PPC__
  474.                 Height     = 240;
  475. #else
  476.                 Height     = 200;
  477. #endif
  478.                 ScreenSize = 100;
  479.             }
  480.         }
  481.         if(str=FindToolType(IconObj->do_ToolTypes,"SCREENSIZE"))
  482.         {
  483.             ScreenSize = atol(str);
  484.         }
  485.         FreeDiskObject(IconObj);
  486. #endif
  487.     }
  488.  
  489.     if(ttypes=(UBYTE**)ArgArrayInit(argc, argv)) {
  490.         str=(char*)ArgString(ttypes, "MAXFPS", "0");
  491.         LimitFPS = atol(str);
  492.  
  493.         str=(char*)ArgString(ttypes, "RESOLUTION", "low");
  494.         if(stricmp(str,"high") == 0) {
  495.             Width      = 640;
  496.             Height     = 480;
  497.             ScreenSize = 66;
  498.             ShowWave   = 1;
  499.         }
  500.         else {
  501.             Width      = 320;
  502. #ifdef __PPC__
  503.             Height     = 240;
  504. #else
  505.             Height       = 200;
  506. #endif
  507.             ScreenSize = 100;
  508.             ShowWave   = 0;
  509.         }
  510.  
  511.         if(str=(char*)ArgString(ttypes, "SCREENSIZE", NULL)) {
  512.             ScreenSize = atol(str);
  513.         }
  514.  
  515.         ArgArrayDone();
  516.     }
  517.  
  518.     if(LimitFPS == 0)  LimitFPS = 999;
  519.     if(LimitFPS > 999) LimitFPS = 999;
  520.  
  521.     if(ScreenSize <  25) ScreenSize =  25;
  522.     if(ScreenSize > 100) ScreenSize = 100;
  523.  
  524.     Cutoff = Height * (100-ScreenSize) / 200;
  525.     if(Cutoff <   1) Cutoff =   1;
  526.     if(Cutoff > 200) Cutoff = 200;
  527.  
  528.     ModeIDtags[1].ti_Data = Width;
  529.     ModeIDtags[2].ti_Data = Height;
  530.  
  531.     HalfHeight = Height/2;
  532.  
  533.     #if defined (__SASC) || defined (__VBCC__)
  534.         #ifdef __PPC__
  535.         PixelD       = PPCAllocVec(Width*Height, MEMF_PUBLIC|MEMF_CLEAR);
  536.         PixelC       = PPCAllocVec(Width*Height, MEMF_PUBLIC|MEMF_CLEAR);
  537.         Colour       = PPCAllocVec(770*4,        MEMF_PUBLIC|MEMF_CLEAR);
  538.         EmptyPointer = PPCAllocVec(512,          MEMF_CHIP|MEMF_CLEAR);
  539.         #else //68k
  540.         PixelD       = AllocVec(Width*Height, MEMF_PUBLIC|MEMF_CLEAR);
  541.         PixelC       = AllocVec(Width*Height, MEMF_PUBLIC|MEMF_CLEAR);
  542.         Colour       = AllocVec(770*4,        MEMF_PUBLIC|MEMF_CLEAR);
  543.         EmptyPointer = AllocVec(512,          MEMF_CHIP|MEMF_CLEAR);
  544.         #endif
  545.     #else
  546.         PixelD       = AllocVecPPC(Width*Height, MEMF_PUBLIC|MEMF_CLEAR, 0);
  547.         PixelC       = AllocVecPPC(Width*Height, MEMF_PUBLIC|MEMF_CLEAR, 0);
  548.         Colour       = AllocVecPPC(770*4,        MEMF_PUBLIC|MEMF_CLEAR, 0);
  549.         EmptyPointer = AllocVecPPC(512,          MEMF_CHIP|MEMF_CLEAR,   0);
  550.     #endif
  551.  
  552.     OpenTimer();
  553.  
  554.     if(PixelD==NULL || PixelC==NULL) {
  555.         ShowRequester("Out of memory for graphics buffers!", "Abort");
  556.         return(FALSE);
  557.     }
  558.  
  559.     srand(time(NULL));
  560.  
  561.     MidR[0] = 255;
  562.     MidG[0] = 255;
  563.     MidB[0] = 127;
  564.  
  565.     MidR[1] = 170;
  566.     MidG[1] = 170;
  567.     MidB[1] = 64;
  568.  
  569.     MidR[2] = 85;
  570.     MidG[2] = 85;
  571.     MidB[2] = 32;
  572.  
  573.     MidR[3] = 0;
  574.     MidG[3] = 0;
  575.     MidB[3] = 0;
  576.  
  577.     MidRdst[0] = (UBYTE)(rand()>>25) + 127;
  578.     MidGdst[0] = (UBYTE)(rand()>>25) + 127;
  579.     MidBdst[0] = (UBYTE)(rand()>>25) + 127;
  580.  
  581.     MidRdst[1] = (UBYTE)(rand()>>25) + 96;
  582.     MidGdst[1] = (UBYTE)(rand()>>25) + 96;
  583.     MidBdst[1] = (UBYTE)(rand()>>25) + 96;
  584.  
  585.     MidRdst[2] = (UBYTE)(rand()>>25) + 64;
  586.     MidGdst[2] = (UBYTE)(rand()>>25) + 64;
  587.     MidBdst[2] = (UBYTE)(rand()>>25) + 64;
  588.  
  589.     DisplayFPS      = 0;
  590.     InfoCount       = 0;
  591.     FrameCountLow   = 0;
  592.     FrameCountHigh  = 0;
  593.     FrameCountWave  = 0;
  594.     FrameCountField = 0;
  595.     TimeWave        = 0;
  596.     DestWaveNum     = 1;
  597.     DestWaveBuffer  = 1;
  598.     WaveMorph       = 0.0;
  599.     LineToCalc      = 0;
  600.     WaveToCalc      = 0;
  601.     WaveToCalc0     = 0;
  602.  
  603.     FieldToCalc     = (UBYTE)(rand()>>24) % NUMFIELDS;
  604.     WaveToCalc1     = (UBYTE)(rand()>>24) % NUMWAVES;
  605. //    FieldToCalc   = NUMFIELDS-1;
  606. //    WaveToCalc1   = NUMWAVES-1;
  607.  
  608.  
  609.     PrepareConstants(FieldToCalc);
  610.  
  611.     MakeCMap();
  612. #ifdef P96
  613.     ModeID=CModeRequestTagList(NULL, ModeIDtags);
  614. #else
  615.     ModeID=BestCModeIDTagList(ModeIDtags);
  616. #endif
  617.     if(ModeID == INVALID_ID) {
  618.         ShowRequester("Could not find suitable screen mode!", "Abort");
  619.         return(FALSE);
  620.   if (ModeID==-1)
  621.         return(FALSE);
  622.     }
  623.  
  624.     PluginScreen=OpenScreenTags(NULL, SA_DisplayID, ModeID, SA_Depth, 8, SA_Width, Width, SA_Height, Height, SA_SharePens, TRUE, SA_ShowTitle, FALSE, SA_Quiet, TRUE, TAG_DONE);
  625.     if(PluginScreen == NULL) {
  626.         ShowRequester("Could not open screen!", "Abort");
  627.         return(FALSE);
  628.     }
  629.     rp = &PluginScreen->RastPort;
  630.     vp = &PluginScreen->ViewPort;
  631.  
  632.     LoadRGB32(vp, Colour);
  633.  
  634.     PluginWin=OpenWindowTags(NULL, WA_CustomScreen, (ULONG)PluginScreen,
  635.                                    WA_Left,         0,
  636.                                    WA_Top,          0,
  637.                                    WA_Width,        Width,
  638.                                    WA_Height,       Height,
  639.                                    WA_SizeGadget,   FALSE,
  640.                                    WA_DragBar,      FALSE,
  641.                                    WA_DepthGadget,  FALSE,
  642.                                    WA_CloseGadget,  FALSE,
  643.                                    WA_Backdrop,     TRUE,
  644.                                    WA_Borderless,   TRUE,
  645.                                    WA_Activate,     TRUE,
  646.                                    WA_AutoAdjust,   TRUE,  // Just to be sure :-)
  647.                                    WA_IDCMP,        IDCMP_RAWKEY | IDCMP_ACTIVEWINDOW | IDCMP_INACTIVEWINDOW,
  648.                                    TAG_DONE);
  649.     if(PluginWin == NULL) {
  650.         ShowRequester("Could not open window!", "Abort");
  651.         return(FALSE);
  652.     }
  653.  
  654.     SetPointer(PluginWin, EmptyPointer, 1, 1, 0, 0);
  655.     SetAPen(rp, 1);
  656.     RectFill(rp, 0, 0, (Width-1), (Height-1));
  657.     SetAPen(rp, 255);
  658.  
  659.     WinMask = 1L << PluginWin->UserPort->mp_SigBit;
  660.  
  661.     InitField(Zoom, Width, Height);
  662.     MakeTitle();
  663.  
  664.     return(TRUE);
  665. }
  666.  
  667. /******************************************************************************/
  668. /* This function will be called when the plugin is shut down. You should free */
  669. /* all previously allocated resources here.                                   */
  670. /******************************************************************************/
  671.  
  672. void PluginExit(void) {
  673.     long i;
  674.  
  675.     if(PluginWin)    CloseWindow(PluginWin);
  676.     if(PluginScreen) CloseScreen(PluginScreen);
  677.     #ifdef __SASC
  678.         if(PixelD)       PPCFreeVec(PixelD);
  679.         if(PixelC)       PPCFreeVec(PixelC);
  680.         if(Colour)       PPCFreeVec(Colour);
  681.         if(EmptyPointer) PPCFreeVec(EmptyPointer);
  682.     #else
  683.      #ifdef __PPC__    
  684.         if(PixelD)       FreeVecPPC(PixelD);
  685.         if(PixelC)       FreeVecPPC(PixelC);
  686.         if(Colour)       FreeVecPPC(Colour);
  687.         if(EmptyPointer) FreeVecPPC(EmptyPointer);
  688.      #else
  689.         if(PixelD)       FreeVec(PixelD);
  690.         if(PixelC)       FreeVec(PixelC);
  691.         if(Colour)       FreeVec(Colour);
  692.         if(EmptyPointer) FreeVec(EmptyPointer);
  693.      #endif
  694.     #endif
  695.  
  696.     CloseTimer();
  697.  
  698.     if(CyberGfxBase)  CloseLibrary(CyberGfxBase);
  699. //    if(GfxBase)       CloseLibrary(GfxBase);
  700.     if(AslBase)       CloseLibrary(AslBase);
  701.     if(IconBase)      CloseLibrary(IconBase);
  702.     if(KeymapBase)    CloseLibrary(KeymapBase);
  703.     if(GadToolsBase)  CloseLibrary(GadToolsBase);
  704. //    if(IntuitionBase) CloseLibrary(IntuitionBase);
  705. }
  706.  
  707. /*******************************************************************************/
  708. /* This is the main Plugin Loop. It will receive a signal matching PluginMask  */
  709. /* each time new spectral data is ready. The data is stored in two arrays,     */
  710. /* UWORD Spec[512] in structures DataL and DataR. The scale is logarithmic,    */
  711. /* 0 means below -96dB, 65535 means 0dB.                                       */
  712. /* No matter how long it takes until your plugin actually processes the data,  */
  713. /* the memory referenced by the array pointers always remains valid!           */
  714. /*                                                                             */
  715. /* Your plugin loop MUST quit when it receives SIGBREAKF_CTRL_C. If you've     */
  716. /* opened a window you should react to the close gadget as well. For full      */
  717. /* screen plugins I strongly recommend checking the ESC key.                   */
  718. /*******************************************************************************/
  719.  
  720. void PluginLoop(void) {
  721.     struct TextExtent te;
  722.     ULONG *PixelL = 0;
  723.     UBYTE *ActPixel;
  724.     ULONG Signals = 0;
  725.     LONG i,j,k;
  726.     LONG l,r;
  727.     LONG x,y;
  728.     UBYTE v;
  729.     UWORD w;
  730.     UBYTE ColorMode;
  731.  
  732.     ULONG    hi,lo,itime,eclock;
  733.     char FPStext[64];
  734.  
  735.     UBYTE Vanilla;
  736.     struct InputEvent ie;
  737.     WORD    RawLen;
  738.     printf("entering main loop\n");
  739.     Wait(SIGBREAKF_CTRL_C | PluginMask);
  740.  
  741.     /* Make a backup of the data pointers */
  742.     PluginRawL    = SpecRawL;
  743.     PluginRawR    = SpecRawR;
  744.     PluginSamples = SampleRaw;
  745.  
  746.     WritePixelArray(PixelC, 0, 0, Width, rp, 0, 0, Width, Height, RECTFMT_LUT8);
  747.     Delay(100);
  748.  
  749.     StartTimer();
  750.  
  751.     InitWave(WaveToCalc0, 0);
  752.     InitWave(WaveToCalc1, 1);
  753.  
  754.     for(;;) {
  755.         /* Wait until there's something to do */
  756.  
  757.         Signals=Wait(SIGBREAKF_CTRL_C | PluginMask | ConfigMask | InfoMask | WinMask | TimerMask);
  758.         if(Signals & TimerMask) {
  759.             WaitIO((struct IORequest *) TimerIO);
  760.         }
  761.  
  762.         /* Break received -> quit at once! */
  763.         if(Signals & SIGBREAKF_CTRL_C) break;
  764.  
  765.         /* Window close gadget hit -> quit as well! */
  766.         if(Signals & WinMask) {
  767.             struct IntuiMessage *imsg;
  768.             BOOL done=0;
  769.  
  770.             while(imsg=(struct IntuiMessage *)GetMsg(PluginWin->UserPort)) {
  771.                 if(imsg->Class == IDCMP_RAWKEY) {
  772.                     ie.ie_Class        = IECLASS_RAWKEY;
  773.                     ie.ie_SubClass     = 0;
  774.                     ie.ie_Code         = imsg->Code;
  775.                     ie.ie_Qualifier    = 0;
  776.                     ie.ie_EventAddress = imsg->IAddress;
  777.                     RawLen = MapRawKey(&ie, &Vanilla, 1, 0);
  778.  
  779.                     switch(imsg->Code) {
  780.                         case 0x45: done=1; break;
  781.                     }
  782.  
  783.                     if(RawLen==1) {
  784.                         switch(Vanilla) {
  785.                             case 'f': DisplayFPS = 1-DisplayFPS; break;
  786.                             case 'w': ShowWave   = 1-ShowWave;   break;
  787.                             case 'i': InfoCount  = 0;            break;
  788. //                        case '+': Cutoff--;                  break;
  789. //                        case '-': Cutoff++;                  break;
  790.                         }
  791.                         if(Cutoff < 1) Cutoff =   1;
  792.                         if(Cutoff > HalfHeight-10) Cutoff = HalfHeight-10;
  793.                         for(i=0; i<Width*Cutoff; i++) {
  794.                             PixelC[i]=PixelD[i]=0;
  795.                         }
  796.                         for(i=Width*(Height-Cutoff); i<Width*Height; i++) {
  797.                             PixelC[i]=PixelD[i]=0;
  798.                         }
  799.                     }
  800.                 }
  801.                 ReplyMsg(imsg);
  802.             }
  803.             if(done) break;
  804.         }
  805.  
  806.         if(Signals & TimerMask) {
  807.             StartTimer();
  808. printf("timer started\n");
  809.       Blur(PixelC, PixelD);
  810.  
  811.             FrameCountLow++;
  812.             if(FrameCountLow > 4) {
  813.                 FrameCountLow = 0;
  814.                 eclock=ReadEClock(&ev2);
  815.                 hi = ev2.ev_hi - ev1.ev_hi;
  816.                 lo = ev2.ev_lo - ev1.ev_lo;
  817.                 itime = hi*eclock+lo;
  818.  
  819.                 if(itime==0) itime=1;
  820.  
  821.                 ev1.ev_hi = ev2.ev_hi;
  822.                 ev1.ev_lo = ev2.ev_lo;
  823.                 ReColor();
  824.             }
  825.  
  826.             FrameCountHigh++;
  827.             if(FrameCountHigh > 600) {
  828.                 FrameCountHigh = 0;
  829.                 ColorMode = (UBYTE)(rand()>>24) % 10;
  830.             printf("ColorMode: %d\n", ColorMode);
  831.                 switch(ColorMode) {
  832.                     case 0:
  833.                     case 1:
  834.                         MidRdst[0] = (UBYTE)(rand()>>25) + 127;
  835.                         MidGdst[0] = (UBYTE)(rand()>>25) + 127;
  836.                         MidBdst[0] = (UBYTE)(rand()>>25) + 127;
  837.  
  838.                         MidRdst[1] = (UBYTE)(rand()>>24) + 0;
  839.                         MidGdst[1] = (UBYTE)(rand()>>24) + 0;
  840.                         MidBdst[1] = (UBYTE)(rand()>>24) + 0;
  841.  
  842.                         MidRdst[2] = (UBYTE)(rand()>>24) + 0;
  843.                         MidGdst[2] = (UBYTE)(rand()>>24) + 0;
  844.                         MidBdst[2] = (UBYTE)(rand()>>24) + 0;
  845.                     break;
  846.  
  847.                     case 2:
  848.                         MidRdst[0] = (UBYTE)(rand()>>24) + 0;
  849.                         MidGdst[0] = (UBYTE)(rand()>>24) + 0;
  850.                         MidBdst[0] = (UBYTE)(rand()>>24) + 0;
  851.  
  852.                         MidRdst[1] = (UBYTE)(rand()>>24) + 0;
  853.                         MidGdst[1] = (UBYTE)(rand()>>24) + 0;
  854.                         MidBdst[1] = (UBYTE)(rand()>>24) + 0;
  855.  
  856.                         MidRdst[2] = (UBYTE)(rand()>>24) + 0;
  857.                         MidGdst[2] = (UBYTE)(rand()>>24) + 0;
  858.                         MidBdst[2] = (UBYTE)(rand()>>24) + 0;
  859.                     break;
  860.  
  861.                     case 3:
  862.                         MidRdst[0] = (UBYTE)(rand()>>25) + 0;
  863.                         MidGdst[0] = (UBYTE)(rand()>>25) + 0;
  864.                         MidBdst[0] = (UBYTE)(rand()>>25) + 0;
  865.  
  866.                         MidRdst[1] = (UBYTE)(rand()>>24) + 0;
  867.                         MidGdst[1] = (UBYTE)(rand()>>24) + 0;
  868.                         MidBdst[1] = (UBYTE)(rand()>>24) + 0;
  869.  
  870.                         MidRdst[2] = (UBYTE)(rand()>>24) + 0;
  871.                         MidGdst[2] = (UBYTE)(rand()>>24) + 0;
  872.                         MidBdst[2] = (UBYTE)(rand()>>24) + 0;
  873.                     break;
  874.  
  875.                     default:
  876.                         MidRdst[0] = (UBYTE)(rand()>>25) + 127;
  877.                         MidGdst[0] = (UBYTE)(rand()>>25) + 127;
  878.                         MidBdst[0] = (UBYTE)(rand()>>25) + 127;
  879.  
  880.                         MidRdst[1] = (UBYTE)(rand()>>25) + 64;
  881.                         MidGdst[1] = (UBYTE)(rand()>>25) + 64;
  882.                         MidBdst[1] = (UBYTE)(rand()>>25) + 64;
  883.  
  884.                         MidRdst[2] = (UBYTE)(rand()>>25) + 32;
  885.                         MidGdst[2] = (UBYTE)(rand()>>25) + 32;
  886.                         MidBdst[2] = (UBYTE)(rand()>>25) + 32;
  887.                     break;
  888.                 }
  889.             }
  890.  
  891.             CalcLine(Zoom2, Width, Height, FieldToCalc);
  892.             LineToCalc++;
  893.             if(LineToCalc > Height-1) LineToCalc = Height-1;
  894.             FrameCountField++;
  895.             
  896.             if(FrameCountField > 500) {
  897.                 FrameCountField=0;
  898.                 LineToCalc = 0;
  899.                 PrevField = FieldToCalc;
  900.                 do {
  901.                     FieldToCalc=(UBYTE)(rand()>>24) % NUMFIELDS;
  902.                 } while (FieldToCalc == PrevField);
  903.  
  904.                 for(j=0; j<Width*Height; j++) {
  905.                     Zoom[j]=Zoom2[j];
  906.                 }
  907.                 PrepareConstants(FieldToCalc);
  908.             }
  909.  
  910.             for(i=Width*Cutoff; i<Width*(Height-Cutoff); i++) {
  911.                 PixelC[i]=PixelD[Zoom[i]];
  912.             }
  913.  
  914.             /* Make a backup of the data pointers */
  915.             PluginRawL    = SpecRawL;
  916.             PluginRawR    = SpecRawR;
  917.             PluginSamples = SampleRaw;
  918.  
  919.             InfoCount++;
  920.             if(InfoCount < 75) MakeTitle();
  921.             else InfoCount=75;
  922.  
  923.             TimeWave++;
  924.             FrameCountWave++;
  925.             CalcWave(WaveToCalc0, 0);
  926.             DrawWave(WaveX,  WaveY,  Width, Height, WaveToCalc0, 0);
  927.             CalcWave(WaveToCalc1, 1);
  928.             DrawWave(WaveX2, WaveY2, Width, Height, WaveToCalc1, 1);
  929.  
  930.             if(FrameCountWave > 200) {
  931.                 if(DestWaveBuffer == 1) WaveMorph += 0.005;
  932.                 else                    WaveMorph -= 0.005;
  933.             }
  934.             if (WaveMorph > 1.0) WaveMorph = 1.0;
  935.             if (WaveMorph < 0.0) WaveMorph = 0.0;
  936.  
  937.             if(FrameCountWave > 400) {
  938.                 FrameCountWave = 0;
  939.                 DestWaveBuffer = 1 - DestWaveBuffer;
  940.                 do {
  941.                     WaveToCalc = (UBYTE)(rand()>>24) % NUMWAVES;
  942.                 } while (WaveToCalc == WaveToCalc0 || WaveToCalc == WaveToCalc1);
  943.                 if(DestWaveBuffer == 1) {
  944.                     WaveToCalc1 = WaveToCalc;
  945.                     InitWave(WaveToCalc1, 1);
  946.                 }
  947.                 else {
  948.                     WaveToCalc0 = WaveToCalc;
  949.                     InitWave(WaveToCalc0, 0);
  950.                 }
  951.             }
  952.  
  953.             for(i=0; i<Width*2; i++) {
  954.                 float xf,yf;
  955.                 ULONG x,y;
  956.                 xf = (float)WaveX[i]*(1.0-WaveMorph) + (float)WaveX2[i]*(WaveMorph);
  957.                 yf = (float)WaveY[i]*(1.0-WaveMorph) + (float)WaveY2[i]*(WaveMorph);
  958.                 x  = (ULONG)xf + Width/2;
  959.                 y  = (ULONG)yf + Height/2;
  960.                 if(x < Width-1) {
  961.                     if(y < Height-1) {
  962.                         if(x > 0) {
  963.                             if(y > 0) {
  964.                                 ActPixel = PixelC + y * Width + x;
  965.                                 *ActPixel=255;
  966.                             }
  967.                         }
  968.                     }
  969.                 }
  970.             }
  971.  
  972.             SetAPen(rp, 0);
  973.             if(ShowWave) WritePixelArray(PixelC, 1, Cutoff+1, Width, rp, 0, Cutoff+1, Width-2, Height-2*Cutoff-2, RECTFMT_LUT8);
  974.             else         WritePixelArray(PixelD, 1, Cutoff+1, Width, rp, 0, Cutoff+1, Width-2, Height-2*Cutoff-2, RECTFMT_LUT8);
  975.             RectFill(rp, 0, 0, Width, Cutoff);
  976.             RectFill(rp, 0, Height-Cutoff-1, Width, Height-1);
  977.  
  978.             if(DisplayFPS) {
  979.                 Move(rp, 0, 20);
  980.                 SetABPenDrMd(rp, 255, 0, JAM2);
  981.                 sprintf(FPStext, "%3ld fps       ", 5*eclock/itime);
  982.                 Text(rp, FPStext, 7);
  983.             }
  984.         }
  985.     }
  986. }
  987.  
  988.  
  989. void Blur(UBYTE *PixelC, UBYTE *PixelD) {
  990.   UBYTE *ActPixel;
  991.   UBYTE *DstPixel;
  992.   UBYTE *AbovePixel, *BelowPixel;
  993.   UBYTE Left, Act, Right;
  994.   WORD w;
  995.   ULONG i;
  996.  
  997.     PixelC += Width*Cutoff;
  998.     PixelD += Width*Cutoff;
  999.  
  1000.   ActPixel   = PixelC+Width+1;
  1001.   AbovePixel = ActPixel-Width;
  1002.   BelowPixel = ActPixel+Width;
  1003.   DstPixel   = PixelD+Width+1;
  1004.  
  1005.   Left  = 0;
  1006.   Act   = 0;
  1007.   Right = 0;
  1008.  
  1009.     for(i=Width*(Cutoff+1); i<(Width*(Height-Cutoff-2)-2); i++) {
  1010.     Right = *(ActPixel+1);
  1011.  
  1012.     w = (Right + Act + Left + *AbovePixel + *BelowPixel) * 3 / 16;
  1013.         if(w<0) w=0;
  1014.     *DstPixel++ = w;
  1015.  
  1016.     ActPixel++;
  1017.     AbovePixel++;
  1018.     BelowPixel++;
  1019.  
  1020.     Left = Act;
  1021.     Act = Right;
  1022.   }
  1023. }
  1024.  
  1025. void ShowRequester(char *Text, char *Button) {
  1026.     struct EasyStruct Req;
  1027.     Req.es_StructSize   = sizeof(struct EasyStruct);
  1028.     Req.es_Flags        = 0;
  1029.   Req.es_Title        = "AmigaAMP Plugin";
  1030.   Req.es_TextFormat   = (UBYTE*)Text;
  1031.   Req.es_GadgetFormat = (UBYTE*)Button;
  1032.     EasyRequestArgs(NULL, &Req, NULL, NULL);
  1033. }
  1034.  
  1035. BOOL OpenTimer(void) {
  1036.     struct EClockVal ev = {0,0};
  1037.  
  1038.     if(TimerMP=(struct MsgPort*)CreatePort(0,0)) {
  1039.         if(TimerIO=(struct timerequest *)CreateIORequest(TimerMP, sizeof(struct timerequest))) {
  1040.             TimerError=OpenDevice("timer.device", UNIT_ECLOCK, (struct IORequest *)TimerIO, 0);
  1041.             if(TimerError==0) {
  1042.  
  1043.                 TimerBase = (struct Library*) &TimerIO->tr_node.io_Device->dd_Library;
  1044.                 EFreq=ReadEClock(&ev);
  1045.  
  1046.                 TimerMask = 1L << TimerMP->mp_SigBit;
  1047.  
  1048.                 return(TRUE);
  1049.             }
  1050.         }
  1051.     }
  1052.     return(FALSE);
  1053. }
  1054.  
  1055. void CloseTimer(void) {
  1056.     if(!TimerError)   CloseDevice((struct IORequest *)TimerIO);
  1057.     if(TimerIO)       DeleteIORequest(TimerIO);
  1058.     if(TimerMP)       DeletePort(TimerMP);
  1059. }
  1060.  
  1061. void StartTimer(void) {
  1062.     TimerIO->tr_node.io_Command = TR_ADDREQUEST;
  1063.     TimerIO->tr_node.io_Flags   = 0;
  1064.     TimerIO->tr_time.tv_secs    = 0;
  1065.     TimerIO->tr_time.tv_micro   = EFreq/LimitFPS;
  1066.     SendIO((struct IORequest *)TimerIO);
  1067. }
  1068.  
  1069. struct MsgPort *MyCreatePort(UBYTE *name, LONG pri) {
  1070.     int sigBit;
  1071.     struct MsgPort *mp;
  1072.  
  1073.     if((sigBit = AllocSignal(-1L)) == -1)    return(NULL);
  1074.  
  1075.     mp = (struct MsgPort*) AllocVec(sizeof(struct MsgPort), MEMF_PUBLIC|MEMF_CLEAR);
  1076.  
  1077.     if(!mp) {
  1078.         FreeSignal(sigBit);
  1079.         return(NULL);
  1080.     }
  1081.  
  1082.     mp->mp_Node.ln_Name = name;
  1083.     mp->mp_Node.ln_Pri  = pri;
  1084.     mp->mp_Node.ln_Type = NT_MSGPORT;
  1085.     mp->mp_Flags        = PA_SIGNAL;
  1086.     mp->mp_SigBit       = sigBit;
  1087.     mp->mp_SigTask      = FindTask(NULL);
  1088.     if(name) AddPort(mp);
  1089.     #if defined (__SASC) || defined (__VBCC__)
  1090.         else NewList(&(mp->mp_MsgList));
  1091.     #else
  1092.         else NewListPPC(&(mp->mp_MsgList));
  1093.     #endif
  1094.  
  1095.     return(mp);
  1096. }
  1097.  
  1098. void MyDeletePort(struct MsgPort *mp) {
  1099.     if(mp->mp_Node.ln_Name) RemPort(mp);
  1100.     mp->mp_SigTask         = (struct Task *) -1;
  1101.     mp->mp_MsgList.lh_Head = (struct Node *) -1;
  1102.     FreeSignal(mp->mp_SigBit);
  1103.     FreeVec(mp); mp=NULL;
  1104. }
  1105.  
  1106. void InitField(LONG *Zoom, ULONG Width, ULONG Height) {
  1107.     LONG i,xs,ys,xd,yd;
  1108.  
  1109.     float scale,greater;
  1110.     float xsf,ysf,xdf,ydf;
  1111.     float rsf,tsf,rdf,tdf;
  1112.     float wf,hf;
  1113.  
  1114.     wf=(float)Width;
  1115.     hf=(float)Height;
  1116.  
  1117.     greater=1.0;
  1118.     if(wf > greater) greater = wf;
  1119.     if(hf > greater) greater = hf;
  1120.  
  1121.     scale = 1.0 / (greater/2.0);
  1122.  
  1123.     for(yd=0; yd<(Height); yd++) {
  1124.         for(xd=0; xd<(Width); xd++) {
  1125.             xdf = (xd - wf/2.0) * scale;
  1126.             ydf = (yd - hf/2.0) * scale;
  1127.  
  1128.             xsf = xdf - xdf * 0.075;
  1129.             ysf = ydf - ydf * 0.075;
  1130.  
  1131.             xs = xsf/scale + wf/2.0;
  1132.             ys = ysf/scale + hf/2.0;
  1133.  
  1134.             if(xs < Width/2)  xs++;
  1135.             if(ys < Height/2) ys++;
  1136.  
  1137.             if(xs < 0)      xs = 0;
  1138.             if(xs > Width)  xs = Width;
  1139.             if(ys < 0)      ys = 0;
  1140.             if(ys > Height) ys = Height;
  1141.  
  1142.             Zoom[Width * yd + xd] = Width * ys + xs;
  1143.         }
  1144.     }
  1145. }
  1146.  
  1147.  
  1148. void MakeCMap(void) {
  1149.     int j,i,c;
  1150.     float r,g,b;
  1151.     float rs,gs,bs;
  1152.  
  1153.     r=255; g=255; b=255;
  1154.  
  1155.     c=255;
  1156.  
  1157.     Colour[0]=256L<<16+0;
  1158.  
  1159.     for(j=0; j<4; j++) {
  1160.         rs = (r - (float)MidR[j]) / 64.0;
  1161.         gs = (g - (float)MidG[j]) / 64.0;
  1162.         bs = (b - (float)MidB[j]) / 64.0;
  1163.         for(i=0; i<64; i++) {
  1164.             Colour[1+3*c+0] = (ULONG)r << 24;
  1165.             Colour[1+3*c+1] = (ULONG)g << 24;
  1166.             Colour[1+3*c+2] = (ULONG)b << 24;
  1167.             r -= rs;
  1168.             g -= gs;
  1169.             b -= bs;
  1170.             c--;
  1171.         }
  1172.     }
  1173.  
  1174. }
  1175.  
  1176. void MakeTitle(void) {
  1177.     long x,y,i,p,s,v,xs,ys;
  1178.     UWORD Blt1[27] = {
  1179.         0x7008,0x0000,0x0000,0x8808,0x0000,0x0000,0x822B,0x1963,
  1180.         0x8E38,0x722C,0xA590,0x5144,0x0A28,0x9913,0xD07C,0x8A28,
  1181.         0x8514,0x5040,0x8A68,0xA594,0xD144,0x71AF,0x1963,0x4E38,
  1182.         0x0000,0x0100,0x0000
  1183.     }; // W=46, H=9
  1184.     UWORD Blt2[54] = {
  1185.         0x8001,0xF400,0x0000,0x0101,0x0000,0x0080,0x8000,0x4400,
  1186.         0x0000,0x0111,0x0000,0x0080,0xB220,0x458E,0x7638,0xC111,
  1187.         0x3967,0x9C80,0xCA20,0x4651,0x4905,0x2092,0x4590,0xA280,
  1188.         0x8940,0x4451,0x493C,0xC0AA,0x7D11,0x3E80,0x8940,0x4451,
  1189.         0x4944,0x20AA,0x4112,0x2080,0x8880,0x4451,0x494D,0x2044,
  1190.         0x4514,0x2280,0xF080,0x444E,0x4934,0xC044,0x3917,0x9C80,
  1191.         0x0100,0x0000,0x0000,0x0000,0x0000,0x0000
  1192.     }; // W=89, H=9
  1193.  
  1194.     xs = (Width-46)/2;
  1195.     ys = Height/2-30-9;
  1196.     s=0;
  1197.     for(y=0; y<9; y++) {
  1198.         x=0;
  1199.         for(i=0; i<3; i++) {
  1200.             for(p=0; p<16; p++) {
  1201.                 x++;
  1202.                 v = Blt1[s] & (1<<(15-p));
  1203.                 if(v) PixelC[(ys+y)*Width+xs+x] = 255;
  1204.             }
  1205.             s++;
  1206.         }
  1207.     }
  1208.     xs = (Width-89)/2;
  1209.     ys = Height/2+30;
  1210.     s=0;
  1211.     for(y=0; y<9; y++) {
  1212.         x=0;
  1213.         for(i=0; i<6; i++) {
  1214.             for(p=0; p<16; p++) {
  1215.                 x++;
  1216.                 v = Blt2[s] & (1<<(15-p));
  1217.                 if(v) PixelC[(ys+y)*Width+xs+x] = 255;
  1218.             }
  1219.             s++;
  1220.         }
  1221.     }
  1222. }
  1223.  
  1224.  
  1225. void ReColor(void) {
  1226.     int i;
  1227.  
  1228.     for(i=0; i<3; i++) {
  1229.         if(MidR[i] > MidRdst[i]) MidR[i] --;
  1230.         if(MidG[i] > MidGdst[i]) MidG[i] --;
  1231.         if(MidB[i] > MidBdst[i]) MidB[i] --;
  1232.         if(MidR[i] < MidRdst[i]) MidR[i] ++;
  1233.         if(MidG[i] < MidGdst[i]) MidG[i] ++;
  1234.         if(MidB[i] < MidBdst[i]) MidB[i] ++;
  1235.     }
  1236.  
  1237.     MakeCMap();
  1238.     LoadRGB32(&PluginScreen->ViewPort, Colour);
  1239. }
  1240.  
  1241. float rnd(float max) {
  1242.     ULONG r;
  1243.     ULONG m;
  1244.  
  1245.     m = (ULONG)(max * 10000.0);
  1246.  
  1247.     r=(rand()>>8) % m;
  1248.  
  1249.     return (float)r/10000.0;
  1250. }
  1251.  
  1252. float sgn(float val) {
  1253.     if(val > 0.0) return  1.0;
  1254.     if(val < 0.0) return -1.0;
  1255.     return 0.0;
  1256. }
  1257.  
  1258. float trnc(float value) {
  1259.     return ceil(value);
  1260. }
  1261.  
  1262. #ifdef __SASC
  1263. void SetPriority(void) {
  1264.     struct TagItem MyTags[2];
  1265.     if(PPCLibBase=OpenLibrary("ppc.library",0)) {
  1266.         MyTags[0].ti_Tag  = PPCTASKTAG_PRIORITY;
  1267.         MyTags[0].ti_Data = 15;
  1268.         MyTags[1].ti_Tag     = TAG_END;
  1269.         CloseLibrary(PPCLibBase);
  1270.     }
  1271. }
  1272. #endif
  1273.  
  1274.  
  1275.